﻿@model WaiGaoQiaoWeb.Models.MenuConfigurationVM
@{
    ViewBag.Title = "MenuConfigurationIndex";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Head
{
    @Html.Css("dp")
    @Html.Js("datepicker")
    <script type="text/javascript" language="javascript">
        var mainheight = document.documentElement.clientHeight;
        var mainWidth = document.documentElement.clientWidth - 10;
        $(document).ready(function () {
            $("#txtStartTime").datepicker({ picker: "<img class='picker' align='middle' src='../../Images/icons/s.gif' alt=''/>" });
            $("#txtEndTime").datepicker({ picker: "<img class='picker' align='middle' src='../../Images/icons/s.gif' alt=''/>" });
            var otherpm = $("#title").height() + $("#findDiv").height(); // 290;
            var gh = mainheight - otherpm - 80;
            var option = {
                height: gh,
                width: mainWidth,
                url: '@Url.Action("GetList")',
                dataType: 'json',
                colModel: [
                    { display: '编号', name: 'MenuConId', width: 60, sortable: false, align: 'left', hide: true, iskey: true },
                    { display: '日期', name: 'MenuConDate', width: 100, sortable: false, align: 'left', hide: false },
                    { display: '类型', name: 'MenuTypeName', width: 100, sortable: false, hide: false, align: 'left' },
                    { display: '名称', name: 'MenuName', width: 100, sortable: false, hide: false, align: 'left' },
                    { display: '单价', name: 'MenuPrice', width: 100, sortable: false, hide: false, align: 'left' },
                    { display: '食堂', name: 'Nodename', width: 100, sortable: false, hide: false, align: 'left' },
                    { display: '餐次', name: 'PeriodName', width: 100, sortable: false, hide: false, align: 'left' }
				],
                buttons: [
                            { name: 'Add', displayname: "新建", title: "新建", bclass: 'add', onpress: toolbarItemAdd_onclick },
                            { name: 'Edit', displayname: "修改", title: "编辑", bclass: 'edit', onpress: toolbarItemEdit_onclick },
                            { name: 'Delete', displayname: "删除", title: "删除", bclass: 'delete', onpress: toolbarItemDel_onclick },
                            { separator: true }
                         ],
                singleselected: false,
                sortname: "Sequence",
                sortorder: "asc",
                title: false,
                usepager: true,
                page: 1,
                rp: 20,
                rpOptions: [10, 15, 20],
                showcheckbox: true,
                selectedonclick: true, //点击行是否选中
                rowbinddata: true
            };
            var instockgrid = $("#MenuConList").flexigrid(option);

            function toolbarItemAdd_onclick(cmd) {
                OpenModelWindow('@Url.Action("AddMenuCon")',
                                   { width: 580, height: 350, caption: "添加菜单配置", onclose: refresh });
            }

            function toolbarItemEdit_onclick(cmd) {
                var items = $(instockgrid).getSelectedRows();
                if (items.length == 0) {
                    showLoadingMsg("请选择要修改的菜单配置!", { left: 400, top: 2 }, true, 3000);
                    return false;
                }
                if (items.length > 1) {
                    showLoadingMsg("只能选择一个要修改的菜单配置!", { left: 400, top: 6 }, true, 3000);
                    return false;
                }
                var date = items[0][1];
                var id = items[0][0];
                OpenModelWindow('@Url.Action("EditMenuCon")?Date=' + date + "&ID=" + id,
                                   { width: 580, height: 350, caption: "修改菜单配置", onclose: refresh });
            }

            function toolbarItemDel_onclick(cmd) {
                var items = $(instockgrid).getSelectedRows();
                if (items.length == 0) {
                    showLoadingMsg("请选择要删除的菜单配置!", { left: 400, top: 6 }, true, 3000);
                    return false;
                }
                if (!confirm("确定要删除菜单配置吗？")) {
                    return false;
                }
                var rowcount = 0;
                for (var i = 0; i < items.length; i++) {
                    var id = items[i][0];
                    $.ajax({
                        type: "POST",
                        url: '@Url.Action("DeleteMenuCon")',
                        data: { id: id },
                        dataType: "json",
                        async: false,
                        success: function (data) {
                            if (data) {
                                rowcount = rowcount + data;
                            }
                        },
                        error: function () { }
                    });
                }
                refresh();
                showLoadingMsg("共有" + rowcount.toString() + "个菜单配置被删除!", { left: 400, top: 6 }, true, 3000);
            }

            $("#btnQueryList").click(function () {
                select();
            });
            function select() {
                var startdate = $("#txtStartTime").val();
                var enddate = $("#txtEndTime").val();
                var type = $("#ddlMenuType").val();
                var name = $("#txtMenuName").val();
                var nodeid = $("#NodeID").val();
                var priid = $("#PeriodCode").val();
                option.query = startdate + "," + enddate + "," + type + "," + name + "," + nodeid + "," + priid;
                option.newp = 0;
                $("#MenuConList").flexOptions(option).flexReload();
            }
            function refresh() {
                $("#MenuConList").flexOptions(option).flexReload();
            }
        });
        function FileUp() {
            document.getElementById("file1").select(); //该对象选取  
            var i = document.selection.createRange().text; //返回选取项的文本内容
            document.getElementById("hi1").value = i;
            var i1 = document.getElementById("hi1").value;
            document.selection.clear();

            $.ajax({
                type: "POST",
                url: '@Url.Action("FileUp")',
                data: { filename: i1 },
                dataType: "json",
                async: false,
                success: function (data) {
                    if (data) {
                        showLoadingMsg("导入成功!", { left: 400, top: 6 }, true, 3000);
                    }
                },
                error: function () { }
            });
        }
        // 匯入確定按鈕
        function checkFile() {
            $("#h_filePath").val($("#importFile").val());

            $("form").attr("action", "Import");
        }
        function checkFile1() {
            $.ajax({
                type: "POST",
                url: '@Url.Action("FileUp1")',
                data: {},
                dataType: "json",
                async: false,
                success: function (data) {
                    if (data == "1") {
//                        showLoadingMsg("导入成功!", { left: 400, top: 6 }, true, 3000);
                        alert("导入成功!");
                    }
                    else {
//                        showLoadingMsg("缺少菜:" + data + "-导入失败", { left: 400, top: 6 }, true, 3000);
                        alert("缺少菜:"+data+"-导入失败!");
                    }
                },
                error: function () { }
            });
        }
    </script>
}
@using (Html.BeginForm("FileUp", "MenuConfiguration", FormMethod.Post, new { enctype = "multipart/form-data", id = "UploadCheOrderPeo" }))
{
    <div id="container">
        <div id="mainContent">
            <div id="title" class="title">
                菜单配置列表</div>
            <div id="findDiv">
                <table>
                    <tr>
                        <td style="text-align: right; width: 60px;">
                            开始日期:
                        </td>
                        <td>
                            @Html.TextBox("txtStartTime", DateTime.Now.Date.AddDays(-30).ToString("yyyy-MM-dd"), new { @ReadOnly = true })
                        </td>
                        <td style="text-align: right; width: 60px;">
                            结束日期:
                        </td>
                        <td>
                            @Html.TextBox("txtEndTime", DateTime.Now.Date.ToString("yyyy-MM-dd"), new { @ReadOnly = true })
                        </td>
                        <td style="text-align: right; width: 60px;">
                            菜单类型:
                        </td>
                        <td>
                            @Html.DropDownList("ddlMenuType",
                                             ViewData["MenuType"] as IEnumerable<SelectListItem>,
                                      new { @style = "width:100px; height:22px; font-size:13px;" })
                        </td>
                        <td>
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: right; width: 60px;">
                            菜单名称:
                        </td>
                        <td>
                            @Html.TextBox("txtMenuName", "", new { @style = "width:100px;" })
                        </td>
                        <td style="text-align: right; width: 60px;">
                            食堂名称:
                        </td>
                        <td>
                            @Html.DropDownListFor(model => model.NodeID,
                                        ViewData["NodeID"] as IEnumerable<SelectListItem>,
                                 new { @style = "width:100px; height:22px; font-size:13px;" })
                        </td>
                        <td style="text-align: right; width: 60px;">
                            餐次名称:
                        </td>
                        <td>
                            @Html.DropDownListFor(model => model.PeriodCode,
                                        ViewData["PeriodCode"] as IEnumerable<SelectListItem>,
                                 new { @style = "width:100px; height:22px; font-size:13px;" })
                        </td>
                        <td>
                            <a id="btnQueryList" class="button" href="javascript:void(0);"><span>查 询</span></a>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="7">
                            @*<form action="/Home/Upload" enctype="multipart/form-data" method="post" id="newform"
                            runat="server">*@ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="file" name="importFile" id="importFile" />
                            @Html.Hidden("h_filePath")
                            <button type="submit" value="上传" id="btnConfirm" onclick="return checkFile();" style="width: 70px;
                                height: 20px">
                                上传
                            </button>
                            <button type="submit" value="导入" id="btnConfirm1" onclick="return checkFile1();"
                                style="width: 70px; height: 20px">
                                导入
                            </button>
                            @* </form>*@
                        </td>
                    </tr>
                </table>
            </div>
            <table id="MenuConList" style="display: none;">
            </table>
        </div>
    </div>
}